package com.alan.designMode.proxy;

/**
 * Created by Alan on 17-8-29
 */
public class GamePlayer implements IGamePlayer{

    private String name = "";

    private IGamePlayer proxy = null;

    public GamePlayer(String name) {
        this.name = name;
    }

    //找到自己的代理
    @Override
    public IGamePlayer getProxy() {
        if(proxy == null){
            this.proxy = new GamePlayerProxy(this);
        }
        return this.proxy;
    }

    @Override
    public void login(String user, String password) {
        if(this.isProxy()){
            System.out.println("name = "+user+",user login success!");
        }else {
            System.out.println("请使用指定代理访问");
        }
    }

    @Override
    public void killBoss() {
        if(this.isProxy()){
            System.out.println("user killBoss...");
        }else {
            System.out.println("请使用指定代理访问");
        }
    }

    @Override
    public void upgrade() {
        if(this.isProxy()){
            System.out.println("user upgrade...");
        }else {
            System.out.println("请使用指定代理访问");
        }
    }

    //校验是否是代理访问
    private boolean isProxy(){
        if(this.proxy == null){
            return false;
        }else {
            return true;
        }
    }



}
